//
//  PrescriptionOrderStatusDetailCell.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2021/8/12.
//  Copyright © 2021 QDSG. All rights reserved.
//

import UIKit

class PrescriptionOrderStatusDetailCell: UITableViewCell {

    func bind(to viewModel: PrescriptionOrderDetailCellViewModel, at indexPath: IndexPath) {
        switch indexPath.row {
        case 0:
            updateUIForFirst(with: viewModel)
        case 1:
            updateUIForSecond(with: viewModel)
        case 2:
            titleLabel.text = "交易流水号："
            infoLabel.text = viewModel.orderId
        case 3:
            titleLabel.text = "创建时间："
            infoLabel.text = viewModel.makeTime
        case 4:
            titleLabel.text = "付款时间："
            infoLabel.text = viewModel.payTime
        case 5:
            updateUIForSixth(with: viewModel)
        case 6:
            updateUIForSeventh(with: viewModel)
        case 7:
            titleLabel.text = "退款完成："
            infoLabel.text = viewModel.backFinishTime
        default:
            break
        }
    }
    
    @IBOutlet private weak var titleLabel: UILabel!
    @IBOutlet private weak var infoLabel: UILabel!
    
    private func updateUIForFirst(with viewModel: PrescriptionOrderDetailCellViewModel) {
        guard let status = viewModel.status else { return }
        switch status {
        case .waitPay, .canceled:
            titleLabel.text = "创建时间："
            infoLabel.text = viewModel.createTime
        default:
            titleLabel.text = "订单配送方式："
            infoLabel.text = viewModel.receiveType.wayText
        }
    }
    
    private func updateUIForSecond(with viewModel: PrescriptionOrderDetailCellViewModel) {
        guard let status = viewModel.status else { return }
        switch status {
        case .canceled:
            titleLabel.text = "取消时间："
            infoLabel.text = viewModel.cancelTime
        default:
            titleLabel.text = viewModel.receiveType == .express ? "配送信息：" : "取药地点："
            infoLabel.text = viewModel.address
        }
    }
    
    private func updateUIForSixth(with viewModel: PrescriptionOrderDetailCellViewModel) {
        guard let status = viewModel.status else { return }
        switch status {
        case .shipped, .reject:
            titleLabel.text = "发药时间："
            infoLabel.text = viewModel.deliveryTime
        case .completed:
            titleLabel.text = viewModel.receiveType == .express ? "发药时间：" : "取药时间："
            infoLabel.text = viewModel.receiveTime
        case .applyRefund,
             .refunded,
             .waitSendOut,
             .sendingBack,
             .waitShipApplyRefund,
             .shippedApplyRefund,
             .completeApplyRefund,
             .waitTakeApplyRefund,
             .waitSendOutUnreceived,
             .waitSendOutReceived:
            titleLabel.text = "申请退药时间："
            infoLabel.text = viewModel.applyBackTime
        default:
            break
        }
    }
    
    private func updateUIForSeventh(with viewModel: PrescriptionOrderDetailCellViewModel) {
        guard let status = viewModel.status else { return }
        switch status {
        case .completed:
            titleLabel.text = "收货时间："
            infoLabel.text = viewModel.receiveTime
        case .sendingBack:
            titleLabel.text = "回寄快递单号："
            infoLabel.text = viewModel.backWaybillNo
        case .refunded:
            titleLabel.text = viewModel.receiveType == .express ? "回寄快递单号：" : "退款完成："
            infoLabel.text = viewModel.receiveType == .express ? viewModel.backWaybillNo : viewModel.backFinishTime
        case .reject:
            titleLabel.text = "拒绝退药原因："
            infoLabel.text = viewModel.rejectBack
        default:
            break
        }
    }
    
}
